//
//  QDRecordMetroTableCell.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/1.
//  Copyright © 2019 YueWen. All rights reserved.
//

import UIKit

/// 地铁乘车记录的cell
final class QDRecordMetroTableCell: NWTableViewCell {
    
    /// 放底部阴影块的视图
    private let backgroundImageView = UIImageView()
    
    /// 显示扫码过闸的标签
    let titleLabel = UILabel()
    /// 显示补站的标签
    let fillLabel = RITLExternLabel()
    /// 开始站
    let startLabel = UILabel()
    /// 开始站前的圆形标注
    private let corStartView = UIView()
    /// 出站
    let endLabel = UILabel()
    /// 出站前的圆形标注
    private let corEndView = UIView()
    
    /// 价格的标签
    let priceLabel = UILabel()
    /// 价格单位的标签
    private let priceUnitLabel = UILabel()
    
    /// 显示进出站时间的标签
    let descTimeLabel = UILabel()
    /// 显示时间的标签
    let timeLabel = UILabel()
    
    /// layer
    /// 位于起始点的layer
    lazy private var verticalLayer: CAShapeLayer = {
        
        let layer = CAShapeLayer()
        layer.strokeColor = #colorLiteral(red: 0.862745098, green: 0.8705882353, blue: 0.862745098, alpha: 1).cgColor
        layer.fillColor = UIColor.clear.cgColor
        layer.anchorPoint = .zero
        let rect = CGRect(x: 30, y: 68, width: 0.5, height: 15)
        layer.path = UIBezierPath(rect: rect).cgPath
        layer.lineWidth = 1
        layer.strokeStart = 0.001
        layer.strokeEnd = 0.499
        layer.lineDashPattern = [NSNumber(integerLiteral: 3)]
        
        return layer
    }()
    
    /// 位于时间间隔的layer
    lazy private var horizontalLayer: CAShapeLayer  = {
        
        let layer = CAShapeLayer()
        layer.strokeColor = #colorLiteral(red: 0.862745098, green: 0.8705882353, blue: 0.862745098, alpha: 1).cgColor
        layer.fillColor = UIColor.clear.cgColor
        layer.anchorPoint = .zero
        let rect = CGRect(x: 27, y: 108, width: UIScreen.main.ritl_width - 80, height: 0.5)
        layer.path = UIBezierPath(rect: rect).cgPath
        layer.lineWidth = 0.5
        layer.strokeStart = 0.001
        layer.strokeEnd = 0.499
        layer.lineDashPattern = [NSNumber(integerLiteral: 4)]
        
        return layer
    }()
    
    
    override func buildView() {
        super.buildView()
        
        contentView.backgroundColor = RecordBackgroundColor
        
        backgroundImageView.image = "mr_background".namedImage?.resizableImage(withCapInsets: UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))
        
        titleLabel.text = "扫码过闸"
        titleLabel.font = Font.light.font(size: 14)
        titleLabel.textColor = QDColors.gray
        
        fillLabel.extensionSpace = 4
        fillLabel.textColor = QDColors.orange
        fillLabel.textAlignment = .center
        fillLabel.font = Font.regular.font(size: 10)
        fillLabel.text = "补站"
        fillLabel.layer.cornerRadius = 7
        fillLabel.layer.borderColor = QDColors.orange.cgColor
        fillLabel.layer.borderWidth = 0.5
        fillLabel.clipsToBounds = true
        
        corStartView.backgroundColor = #colorLiteral(red: 0.3215686275, green: 0.8, blue: 0.4156862745, alpha: 1)
        corStartView.layer.cornerRadius = 3.5
        
        startLabel.textColor = #colorLiteral(red: 0.3960784314, green: 0.4, blue: 0.3960784314, alpha: 1)
        startLabel.font = Font.regular.font(size: 14)
        startLabel.text = "石老人浴场"
        
        corEndView.backgroundColor = #colorLiteral(red: 0.9803921569, green: 0.4784313725, blue: 0.4784313725, alpha: 1)
        corEndView.layer.cornerRadius = 3.5
        
        endLabel.textColor = #colorLiteral(red: 0.3960784314, green: 0.4, blue: 0.3960784314, alpha: 1)
        endLabel.font = Font.regular.font(size: 14)
        endLabel.text = "石老人浴场"
        
        priceLabel.text = "8"
        priceLabel.font = Font.medium.font(size: 32)
        priceLabel.textColor = QDColors.black
        
        priceUnitLabel.text = "元"
        priceUnitLabel.font = Font.medium.font(size: 14)
        priceUnitLabel.textColor = QDColors.black
        
        descTimeLabel.text = "进出站时间："
        descTimeLabel.font = Font.light.font(size: 14)
        descTimeLabel.textColor = QDColors.gray2
        
        timeLabel.text = "2018-10-11  14:22-14:52"
        timeLabel.font = Font.light.font(size: 14)
        timeLabel.textColor = QDColors.gray2
        
        backgroundImageView.layer.addSublayer(horizontalLayer)
        backgroundImageView.layer.addSublayer(verticalLayer)
        
        contentView.addSubview(backgroundImageView)
        contentView.addSubview(titleLabel)
        contentView.addSubview(fillLabel)
        contentView.addSubview(corStartView)
        contentView.addSubview(corEndView)
        contentView.addSubview(startLabel)
        contentView.addSubview(endLabel)
        contentView.addSubview(priceUnitLabel)
        contentView.addSubview(priceLabel)
        contentView.addSubview(descTimeLabel)
        contentView.addSubview(timeLabel)
        
        backgroundImageView.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(13)
            make.right.equalToSuperview().inset(13)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(40)
            make.height.equalTo(20)
            make.top.equalToSuperview().offset(23)
        }
        
        fillLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(titleLabel)
            make.left.equalTo(titleLabel.snp.right).offset(4)
            make.height.equalTo(14)
        }
        
        corStartView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(40)
            make.height.width.equalTo(7)
            make.top.equalToSuperview().offset(58)
        }
        
        startLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(55)
            make.height.equalTo(20)
            make.top.equalTo(titleLabel.snp.bottom).offset(8)
        }
        
        corEndView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(40)
            make.height.width.equalTo(7)
            make.top.equalToSuperview().offset(87)
        }
        
        endLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(55)
            make.height.equalTo(20)
            make.top.equalTo(titleLabel.snp.bottom).offset(36)
        }
        
        priceLabel.snp.makeConstraints { (make) in
            make.right.equalTo(priceUnitLabel.snp.left).offset(-1)
            make.height.equalTo(45)
            make.top.equalToSuperview().offset(54)
        }
        
        priceUnitLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().inset(40)
            make.height.equalTo(20)
            make.top.equalToSuperview().offset(71)
        }
        
        descTimeLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(40)
            make.height.equalTo(20)
            make.top.equalToSuperview().offset(117)
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.height.equalTo(20)
            make.right.equalToSuperview().inset(48)
            make.top.equalToSuperview().offset(117)
        }
    }
}
